package com.cool.reggie.utils;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;

import java.io.Serializable;
import java.util.HashMap;

/**
 * @Author ifredomvip@gmail.com
 * @Date 2022/7/1 14:33
 * @Version 1.0.0
 * @Description
 **/
@ApiModel
public class ResultData extends HashMap<String, Object> {

    private static final long serialVersionUID = -187570094792271948L;

    /**
     * 操作结果的状态码，具体定义参见ResponseCode类的定义
     */
    @ApiModelProperty(value = "状态码 - 0业务错误 1成功 99登录失效 98服务器内部错误")
    public static final String CODE = "code";

    /**
     * 操作结果的描述信息，可作为页面提示信息使用
     */
    @ApiModelProperty(value = "描述")
    public static final String MSG = "msg";

    /**
     * 返回的业务数据
     */
    @ApiModelProperty(value = "业务数据")
    public static final String DATA = "data";

    /**
     * 无参构造
     */
    public ResultData() {
    }

    public ResultData(int code, String msg, Object data) {
        super.put(CODE, code);
        super.put(MSG, msg);
        super.put(DATA, data);
    }

    public static ResultData ok() {
        return ResultData.ok(ResultCode.SUCCESS_MSG);
    }

    public static ResultData ok(Object data) {
        return ResultData.ok(ResultCode.SUCCESS_MSG, data);
    }

    public static ResultData ok(String msg, Object data) {
        return ResultData.ok(ResultCode.SUCCESS, msg, data);
    }

    public static ResultData ok(int code, String msg, Object data) {
        return new ResultData(code, msg, data);
    }

    public static ResultData error() {
        return ResultData.error(ResultCode.FAIL_MSG);
    }

    public static ResultData error(String msg) {
        return ResultData.error(ResultCode.FAIL, msg);
    }

    public static ResultData error(int code, String msg) {
        return ResultData.error(code, msg, null);
    }

    public static ResultData error(int code, String msg, Object data) {
        return new ResultData(code, msg, data);
    }


    public String getMsg() {
        return MSG;
    }
    public String getCode() {
        return CODE;
    }
    public String getData() {
        return DATA;
    }
}
